home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / app / SaveURIDialog.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  9.9 KB  |  291 lines

  1. package com.extensibility.app;
  2.  
  3. import com.extensibility.plugin.PluginRegistry;
  4. import com.extensibility.plugin.api.LoginPanel;
  5. import com.extensibility.plugin.api.ResLocationContext;
  6. import com.extensibility.plugin.api.ResLocationPlugin;
  7. import com.extensibility.plugin.api.ResLocationPluginPanel;
  8. import com.extensibility.plugin.api.TreeBrowseContext;
  9. import com.extensibility.plugin.api.TreeBrowseListener;
  10. import com.extensibility.plugin.api.TreeBrowseModel;
  11. import com.extensibility.plugin.api.URIScheme;
  12. import com.extensibility.rock.QuietBtn;
  13. import com.extensibility.rock.RAction;
  14. import com.extensibility.rock.RDialog;
  15. import com.extensibility.util.ArrayHelp;
  16. import com.extensibility.xml.URI;
  17. import com.extensibility.xml.URISchemeRegistry;
  18. import java.awt.BorderLayout;
  19. import java.awt.Component;
  20. import java.awt.Container;
  21. import java.awt.Dialog;
  22. import java.awt.Dimension;
  23. import java.awt.Frame;
  24. import java.awt.Window;
  25. import java.io.File;
  26. import java.util.Enumeration;
  27. import java.util.Vector;
  28. import javax.swing.Box;
  29. import javax.swing.Icon;
  30. import javax.swing.JButton;
  31. import javax.swing.JDialog;
  32. import javax.swing.JTabbedPane;
  33. import javax.swing.KeyStroke;
  34. import javax.swing.border.EmptyBorder;
  35. import javax.swing.event.ChangeEvent;
  36. import javax.swing.event.ChangeListener;
  37.  
  38. public class SaveURIDialog extends RDialog implements ResLocationContext, ChangeListener {
  39.    protected static final KeyStroke ENTER_KEY = KeyStroke.getKeyStroke(10, 0);
  40.    protected static final KeyStroke ESCAPE_KEY = KeyStroke.getKeyStroke(27, 0);
  41.    Frame myParent = null;
  42.    JTabbedPane tabs;
  43.    URI baseURI;
  44.    URI uri;
  45.    protected boolean bSaving = true;
  46.    protected boolean prepared = false;
  47.    String okID = null;
  48.    String cancelID = null;
  49.    JButton okButton = null;
  50.    JButton cancelButton = null;
  51.    String title = null;
  52.    String suffix;
  53.    RAction okAction = new 4(this);
  54.    RAction cancelAction = new 5(this);
  55.    private static final int VERSION_NUMBER = 1;
  56.  
  57.    public void stateChanged(ChangeEvent var1) {
  58.       Component var2 = this.tabs.getSelectedComponent();
  59.       ResLocationPluginPanel var3 = (ResLocationPluginPanel)var2;
  60.       var3.panelShown();
  61.    }
  62.  
  63.    public URI getURI() {
  64.       return this.uri;
  65.    }
  66.  
  67.    public SaveURIDialog(Frame var1, URI var2) {
  68.       super(var1, true);
  69.       if (var2 == null) {
  70.          this.baseURI = new URI();
  71.       } else {
  72.          this.baseURI = var2;
  73.       }
  74.  
  75.       this.myParent = var1;
  76.    }
  77.  
  78.    public SaveURIDialog(Frame var1, URI var2, String var3) {
  79.       super(var1, true);
  80.       this.title = var3;
  81.       if (var2 == null) {
  82.          this.baseURI = new URI();
  83.       } else {
  84.          this.baseURI = var2;
  85.       }
  86.  
  87.       this.myParent = var1;
  88.    }
  89.  
  90.    public URI getBaseURI() {
  91.       return this.baseURI;
  92.    }
  93.  
  94.    public void show() {
  95.       this.ensurePrepared();
  96.       super.show();
  97.    }
  98.  
  99.    public void ensurePrepared() {
  100.       if (!this.prepared) {
  101.          this.prepared = true;
  102.          this.prepare();
  103.       }
  104.  
  105.    }
  106.  
  107.    protected void prepare() {
  108.       this.prepared = true;
  109.       if (this.title == null) {
  110.          this.title = UI.getString("dialog.save.uri.title");
  111.       }
  112.  
  113.       ((Dialog)this).setTitle(this.title);
  114.       ((JDialog)this).getContentPane().setLayout(new BorderLayout());
  115.       Box var1 = Box.createHorizontalBox();
  116.       this.fillButtonBox(var1);
  117.       Box var2 = Box.createVerticalBox();
  118.       ((Container)var2).add(var1);
  119.       ((Container)var2).add(Box.createVerticalStrut(8));
  120.       this.tabs = new JTabbedPane();
  121.       this.tabs.setBorder(new EmptyBorder(8, 8, 8, 8));
  122.       if (this.baseURI == null) {
  123.          this.suffix = null;
  124.       } else {
  125.          this.suffix = this.baseURI.getShortName();
  126.          int var3 = this.suffix.lastIndexOf(".");
  127.          if (var3 >= 0) {
  128.             this.suffix = this.suffix.substring(var3 + 1);
  129.          } else {
  130.             this.suffix = null;
  131.          }
  132.       }
  133.  
  134.       Vector var10 = new Vector();
  135.       PluginRegistry var4 = PluginRegistry.getRegistry();
  136.       int var5 = var4.getPluginApiCount("ResourceLocation01");
  137.  
  138.       for(int var6 = 0; var6 < var5; ++var6) {
  139.          ResLocationPlugin var7 = (ResLocationPlugin)var4.getNthPlugin("ResourceLocation01", var6);
  140.          var7.initialize(this);
  141.          if (this.pluginIsAppropriate(var7)) {
  142.             var10.addElement(var7);
  143.          }
  144.       }
  145.  
  146.       ArrayHelp.sort(0, var10.size(), new 6(var10, (SaveURIDialog)null, var10));
  147.       boolean var11 = true;
  148.       Enumeration var8 = var10.elements();
  149.  
  150.       while(var8.hasMoreElements()) {
  151.          ResLocationPlugin var9 = (ResLocationPlugin)var8.nextElement();
  152.          this.tabs.addTab(var9.getName(), (Icon)null, this.getPluginPanel(var9), (String)null);
  153.          if (var11) {
  154.             this.tabs.setSelectedIndex(0);
  155.             var11 = false;
  156.          }
  157.       }
  158.  
  159.       this.tabs.getModel().addChangeListener(this);
  160.       ((JDialog)this).getContentPane().add(this.tabs, "Center");
  161.       ((JDialog)this).getContentPane().add(var2, "South");
  162.       ((JDialog)this).getRootPane().registerKeyboardAction(this.cancelAction, "", ESCAPE_KEY, 2);
  163.       ((JDialog)this).getRootPane().registerKeyboardAction(this.okAction, "", ENTER_KEY, 2);
  164.       this.stateChanged((ChangeEvent)null);
  165.       ((Window)this).pack();
  166.       ((Component)this).setLocation(100, 100);
  167.       Dimension var12 = ((Component)this).getSize();
  168.       ((Component)this).setSize(new Dimension(Math.max(var12.width, 500), var12.height));
  169.    }
  170.  
  171.    protected void fillButtonBox(Box var1) {
  172.       ((Container)var1).add(Box.createHorizontalGlue());
  173.       String var2 = this.cancelID != null ? this.cancelID : "dialog.cancel";
  174.       this.cancelButton = new JButton(UI.getString(var2));
  175.       this.cancelButton.addActionListener(this.cancelAction);
  176.       this.cancelButton.setMnemonic(UI.getMnemonic("dialog.cancel"));
  177.       ((Container)var1).add(this.cancelButton);
  178.       ((Container)var1).add(Box.createHorizontalStrut(8));
  179.       var2 = this.okID != null ? this.okID : (this.bSaving ? "dialog.save" : "dialog.open");
  180.       this.okButton = new JButton(UI.getString(var2));
  181.       this.okButton.setMnemonic(UI.getMnemonic(var2));
  182.       this.okButton.addActionListener(this.okAction);
  183.       ((Container)var1).add(this.okButton);
  184.       ((Container)var1).add(Box.createHorizontalStrut(8));
  185.    }
  186.  
  187.    protected boolean pluginIsAppropriate(ResLocationPlugin var1) {
  188.       return var1.canSave(this.suffix);
  189.    }
  190.  
  191.    protected ResLocationPluginPanel getPluginPanel(ResLocationPlugin var1) {
  192.       return var1.getSavePanel(this);
  193.    }
  194.  
  195.    public int getVersion() {
  196.       return 1;
  197.    }
  198.  
  199.    public boolean hasCapability(String var1) {
  200.       return false;
  201.    }
  202.  
  203.    public void setOKEnabled(boolean var1) {
  204.       this.ensurePrepared();
  205.       this.okButton.setEnabled(var1);
  206.    }
  207.  
  208.    public void setOKID(String var1) {
  209.       this.okID = var1;
  210.    }
  211.  
  212.    public void setCancelID(String var1) {
  213.       this.cancelID = var1;
  214.    }
  215.  
  216.    public URIScheme confirmInput() {
  217.       Component var1 = this.tabs.getSelectedComponent();
  218.       ResLocationPluginPanel var2 = (ResLocationPluginPanel)var1;
  219.       URISchemeRegistry var3 = URI.getRegistry();
  220.       return var2.getValidSchemeResult(var3);
  221.    }
  222.  
  223.    public TreeBrowseContext createBrowsing(TreeBrowseModel var1, TreeBrowseListener var2) {
  224.       return new BrowseHelper(var1, var2);
  225.    }
  226.  
  227.    public JButton createQuietButton(String var1, Icon var2) {
  228.       return new QuietBtn(var1, var2, (RAction)null);
  229.    }
  230.  
  231.    public LoginPanel getLoginPanel(String[] var1, String var2, String var3, String var4) {
  232.       return new LoginPanelImpl(var1, var2, var3, var4);
  233.    }
  234.  
  235.    public void okSave(URIScheme var1) {
  236.       this.uri = new URI(var1);
  237.       ((Window)this).dispose();
  238.    }
  239.  
  240.    public void okOpen(URIScheme var1) {
  241.    }
  242.  
  243.    public void cancel() {
  244.       this.uri = null;
  245.       ((Window)this).dispose();
  246.    }
  247.  
  248.    public void setDefault(String var1) {
  249.       this.ensurePrepared();
  250.  
  251.       for(int var2 = 0; var2 < this.tabs.getTabCount(); ++var2) {
  252.          Component var3 = this.tabs.getComponentAt(var2);
  253.          if (var3 instanceof ResLocationPluginPanel) {
  254.             ((ResLocationPluginPanel)var3).setDefault(var1);
  255.          }
  256.       }
  257.  
  258.    }
  259.  
  260.    public void setPrompt(String var1) {
  261.       this.ensurePrepared();
  262.  
  263.       for(int var2 = 0; var2 < this.tabs.getTabCount(); ++var2) {
  264.          Component var3 = this.tabs.getComponentAt(var2);
  265.          if (var3 instanceof ResLocationPluginPanel) {
  266.             ((ResLocationPluginPanel)var3).setPrompt(var1);
  267.          }
  268.       }
  269.  
  270.    }
  271.  
  272.    public File askFile(String var1, String[] var2) {
  273.       ((Component)this).setVisible(false);
  274.       return DialogFactory.askFile(this.myParent, var1, var2);
  275.    }
  276.  
  277.    public URIScheme getBaseLocation() {
  278.       return this.baseURI.getSchemeObject();
  279.    }
  280.  
  281.    public URIScheme createResLocation(URIScheme var1, String var2) {
  282.       URI var3 = var1 != null && var1.hasPersistence() ? new URI(var1) : null;
  283.       return (new URI(var3, var2)).getSchemeObject();
  284.    }
  285.  
  286.    public URIScheme createResLocation(File var1) {
  287.       URI var2 = new URI(var1);
  288.       return var2.getSchemeObject();
  289.    }
  290. }
  291.